package com.literature.threeGroup.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.literature.threeGroup.mapper.CoverMapper;
import com.literature.threeGroup.mapper.LogMapper;
import com.literature.threeGroup.pojo.Cover;
import com.literature.threeGroup.pojo.CoverOrder;
import com.literature.threeGroup.pojo.Log;
import com.literature.threeGroup.service.LogsService;
import com.literature.threeGroup.util.IdWorker;
import com.literature.threeGroup.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;

/**
 * @author VULCAN
 * @create 2020-01-07 14:30
 * @desc
 **/
@Service
public class LogsServiceImpl implements LogsService {

    @Autowired
    private LogMapper logMapper;
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private CoverMapper coversMapper;
    /**
     * @name  日志列表
     * @Author VULCAN
     * @Date 2020/1/9 15:58
     */
    @Override
    public List<Log> findlog(Log log) {
        return logMapper.findlog(log);
    }
    /**
      * @name  日志列表 +分页 +模糊
     * @Author VULCAN
     * @Date 2020/1/22 13:14
     */
    @Override
    public PageResult findallpage(Log log , int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
       Page<Log> findlog = (Page<Log>) logMapper.findlog(log);
        return new PageResult(findlog.getTotal(),findlog.getResult());
    }
    /**
     * @name  批量删除
     * @Author VULCAN
     * @Date 2020/1/17 9:47
     */
    @Override
    public String logbulkdel(String[] ids) {
        for (String id : ids) {
            logMapper.logdel(id+"");
        }
        return null;
    }
    /**
     * @name  logcount
     * @Author VULCAN
     * @Date 2020/1/11 10:01
     */
    @Override
    public List logcount() {
        return logMapper.logcount();
    }
    /**
     * @name  驳回日志
     * @Author VULCAN
     * @Date 2020/2/2 11:06
     */
    @Override
    public void logturn(Log log , String[] ids) throws UnknownHostException {
        for (String id : ids) {
            Cover cover = coversMapper.selectByPrimaryKey(id + "");
            //驳回原因
            log.setLogId(idWorker.nextId()+"");
            log.setLogDate(new Date());
            InetAddress ip4 = Inet4Address.getLocalHost();
            log.setLogIp(ip4.getHostAddress());
            log.setLogType("审核驳回");
            log.setLogName(cover.getCoverName());
            logMapper.insert(log);
        }

    }
}
